/**
 * Created by lbs on 2017/3/20.
 */


function formatTen(num) {
    return num > 9 ? (num + "") : ("0" + num);
}

function formatDate(date) {
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    //var hour = date.getHours();
    //var minute = date.getMinutes();
    //var second = date.getSeconds();
    return year + "-" + formatTen(month) + "-" + formatTen(day);
}

//获取当前时间
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();

    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }

    if (hour > 0 && hour <= 9) {
        hour = "0" + hour;
    }
    if (hour == 0) (
        hour = "00"
    )

    if (minute > 0 && minute <= 9) {
        minute = "0" + minute
    }
    if (minute == 0) {
        minute = "00";
    }

    if (second > 0 && second <= 9) {
        second = "0" + second;
    }
    if (second == 0) {
        second = "00";
    }

    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + "T" + hour + seperator2 + minute
        + seperator2 + second;
    return currentdate;
}

//获取当前日期
function getNowDate() {
    var date = new Date();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();

    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    return date.getFullYear() + '-' + month + '-' + strDate;
}


//视频时长
function getVideoLength(id1, id2, id3) {
    var one = parseInt(id1.val());
    if (id1.val() == '') {
        one = parseInt(0);
    }
    if (one > 0 && one <= 9) {
        one = '0' + one;
    }
    if (one == 0) {
        one = '00';
    }

    var two = parseInt(id2.val());
    if (id2.val() == '') {
        two = 0;
    }
    if (two > 0 && two <= 9) {
        two = '0' + two;
    }
    if (two == 0) {
        two = '00';
    }

    var three = parseInt(id3.val());
    if (id3.val() == '') {
        three = 0;
    }
    if (three > 0 && three <= 9) {
        three = '0' + three;
    }
    if (three == 0) {
        three = '00';
    }

    return one + ':' + two + ':' + three;
}

//登录验证
function loginCheck(url, redirectToUrl) {
    $.get(url, function (data) {
        try {
            var dataArr = JSON.parse(data);
            if (dataArr.code = 'NO_LOGIN') {
                window.location.href = redirectToUrl;
            }
        } catch (e) {

        }
    })
}

function jumpLogin(code) {
    if (code == 'NO_LOGIN') {
        if (confirm('登录超时，是否跳转到登录页面')) {
            window.location.href = '/manage/login.html'
        }
    }
}

var client = new OSS.Wrapper({
    region: 'oss-cn-hangzhou',
    accessKeyId: 'LTAIKc4SmxqXnWjb',
    accessKeySecret: 'n2mZHgH4SfHCaTOips4iuR2h4NOsjo',
    bucket: 'ddup-img1'
});
